package com.sample.trace.interce;

import com.sample.trace.consts.TraceConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OpenFeignRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        String traceId = MDC.get(TraceConstants.TRACE_ID_KEY);
        String serverName = MDC.get(TraceConstants.SERVER_NAME);
        requestTemplate.header(TraceConstants.TRACE_ID_KEY, traceId);
        requestTemplate.header(TraceConstants.UP_SERVER, serverName);
    }
}
